package com.mazaiting.redeye.domain;

import com.mazaiting.redeye.interfaces.IJsonBean;
import com.mazaiting.redeye.utils.JackJsonUtil;

/***
 *
 *
 *                                                    __----~~~~~~~~~~~------___
 *                                   .  .   ~~//====......          __--~ ~~
 *                   -.            \_|//     |||\\  ~~~~~~::::... /~
 *                ___-==_       _-~o~  \/    |||  \\            _/~~-
 *        __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *    _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *  .~       .~       |   \\ -_    /  /-   /   ||      \   /
 * /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 * |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *          '         ~-|      /|    |-~\~~       __--~~
 *                      |-~~-_/ |    |   ~\_   _-~            /\
 *                           /  \     \__   \/~                \__
 *                       _--~ _/ | .-~~____--~-/                  ~~==.
 *                      ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                 -_     ~\      ~~---l__i__i__i--~~_/
 *                                 _-~-__   ~)  \--______________--~~
 *                               //.-~~~-~_--~- |-------~~~~~~~~
 *                                      //.-~~~--\
 *                               神兽保佑
 *                              代码无BUG!
 * @author mazaiting
 * @date 2019-06-27
 * @decription 请求 Bean
 */
public class Request<T> implements IJsonBean {
    /**
     * 令牌
     */
    private String token;
    /**
     * 泛型数据
     */
    private T data;

    public Request() {
    }

    public Request(String token) {
        this.token = token;
    }

    public Request(T data) {
        this.data = data;
    }

    public Request(String token, T data) {
        this.token = token;
        this.data = data;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Request{" +
                "token='" + token + '\'' +
                ", data=" + data +
                '}';
    }

    @Override
    public String toJson() {
        return JackJsonUtil.toJson(this);
    }

    @SuppressWarnings("unchecked")
    @Override
    public Request<T> fromJson(String content) {
        return JackJsonUtil.formJson(content, Request.class);
    }
}
